package cc.vv.btpartyjob.partymanager.activity

import android.content.Intent
import android.text.TextUtils
import android.util.Log
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.util.UserInfoManageUtil
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.globle.IntentJniKey
import cc.vv.btpartyjob.jnimodule.moudel.resp.OrgDetailResponseObj
import cc.vv.btpartyjob.jnimodule.server.JniDataServer
import cc.vv.btpartyjob.jnimodule.server.JniStartActivity
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.StreetMeetingJianJieIntroActivityDelegate
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 街道联席会议组织查询信息简介
 * Created by Chen.qi on 2018/10/27.
 */
class StreetMeetingJianJieIntroActivity : BaseActivityMVP<StreetMeetingJianJieIntroActivityDelegate>() {

    private var streetId: String? = null

    override fun initData() {
        viewDelegate?.setTopBarTitle("组织简介")
        if (TextUtils.isEmpty(streetId)) {
            val userInfo = UserInfoManageUtil.getUserInfo()
            val userOrgList = userInfo?.userOrgList
            if (null != userOrgList) {
                for (i in userOrgList.indices) {
                    if (userOrgList[i].type == 1) {
                        streetId = userOrgList[i].id
                        break
                    }
                }
            }
        }
        Log.e("lk_chen", "result看看街道-----=="+ streetId);
        JniDataServer.getOrganDetail(streetId)
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
                JniStartActivity.startIntentOrganActivity(this@StreetMeetingJianJieIntroActivity, 1, 1, 100)
            }
        })

    }

    override fun getDelegateClass(): Class<StreetMeetingJianJieIntroActivityDelegate> {
        return StreetMeetingJianJieIntroActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is OrgDetailResponseObj -> {
                val data = obj.data
                viewDelegate?.setUnitName(data?.name)
                viewDelegate?.setUnitPhone(data?.mobile)
                viewDelegate?.setUnitAddress(data?.location)
                viewDelegate?.setPrincipalData(data.adminList)

            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (null == data) {
            return
        }
        if (requestCode == 100 && resultCode == 101) {
            streetId = data.getStringExtra(IntentJniKey.INTENT_KEY_ORGAN_ID)
            JniDataServer.getOrganDetail(streetId)
        }
    }


}